/*******************************************************************************
 * Copyright 2009, 2010 Omnidroid - http://code.google.com/p/omnidroid 
 *  
 * Licensed under the Apache License, Version 2.0 (the "License"); 
 * you may not use this file except in compliance with the License. 
 * You may obtain a copy of the License at 
 *  
 *     http://www.apache.org/licenses/LICENSE-2.0 
 *     
 * Unless required by applicable law or agreed to in writing, software 
 * distributed under the License is distributed on an "AS IS" BASIS, 
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
 * See the License for the specific language governing permissions and 
 * limitations under the License. 
 *******************************************************************************/
package edu.nyu.cs.omnidroid.app.controller.events;

import edu.nyu.cs.omnidroid.app.controller.Event;
import android.content.Intent;

/**
 * This class encapsulates a WeatherChanged event. It wraps the intent that
 * triggered this event and provides access to any attribute data associated
 * with it.
 */
public class WeatherChangedEvent extends Event {
	/** Event name (to match record in database) */
	public static final String APPLICATION_NAME = "WEATHER";
	public static final String EVENT_NAME = "Weather Changed";
	public static final String ACTION_NAME = "WEATHER_CHANGED";

	/**
	 * This constant is already deprecated, use the the global attribute
	 * {@link Event#ATTRIBUTE_LOCATION} instead.
	 */
	@Deprecated
	public static final String ATTRIBUTE_CURRENT_WEATHER = "Current Weather";

	  /** Attribute field names */
	  public static final String ATTRIB_TEMPERATURE = "Temperature";
	  public static final String ATTRIB_HUMIDITY = "Humidity";
	  public static final String ATTRIB_CONDITION = "Condition";
	  public static final String ATTRIB_WIND = "Wind";	  
	  
	/**
	 * Cache any values that are requested because it is likely they will be
	 * asked for again
	 */
	public String temperature;
	public String humidity;
	public String condition;
	public String wind;

	/**
	 * Constructs a new WeatherChanged object that holds an WeatherChanged event
	 * fired intent. This intent holds the data needed to check the event
	 * against user defined rules.
	 * 
	 * @param intent
	 *            the intent received when the WeatherChanged event was fired
	 */
	public WeatherChangedEvent(Intent intent) {
		super(APPLICATION_NAME, EVENT_NAME, intent);

		temperature = intent.getStringExtra("temperature");
		humidity = intent.getStringExtra("humidity");
		condition = intent.getStringExtra("condition");
		wind = intent.getStringExtra("wind");
	}
	
	
	  @Override
	  public String getAttribute(String attributeName) throws IllegalArgumentException {
	    if (attributeName.equals(WeatherChangedEvent.ATTRIB_TEMPERATURE)) 
	    {
	    	return temperature;
	    }
	    else if (attributeName.equals(WeatherChangedEvent.ATTRIB_HUMIDITY)) 
	    {
	    	return humidity;
	    }
	    else if (attributeName.equals(WeatherChangedEvent.ATTRIB_CONDITION)) 
	    {
	    	return condition;
	    }
	    else if (attributeName.equals(WeatherChangedEvent.ATTRIB_WIND)) 
	    {
	    	return wind;
	    }
	    else 
	    {
	      return super.getAttribute(attributeName);
	    }
	  }
	
}
